﻿@model BuildSystemApplication.Models.Build.QFormModel

@{
    ViewBag.Title = "QForm";
}

<script type="text/javascript">
        function SelectSection(ctl) {
            document.getElementById('loadForm').value = '1';
            $('form#ajaxForm').submit();
        }
    </script>
    <div>
        @using (Ajax.BeginForm("BuildForm", new {}, new AjaxOptions() { HttpMethod = "POST" }, new { id = "ajaxForm" }))
        {
            <input type="hidden" name="loadForm" id="loadForm" value="" />
            <fieldset style="border:1px solid silver; padding:5px;">
                <legend></legend>
                Category:
            @foreach (var item in Model.Category)
            {
                @(Html.CheckBox("checkCategory_" + item.Key, item.Value))
                @(item.Key + "  ")
            }
                <hr />
                Section:
            @foreach (var item in Model.Section)
            {
                @(Html.RadioButton("radSection", item.Key, item.Value, new { onclick = "SelectSection(this)", @style = "width: 20px;" }))
                @(item.Key + "  ")
            }
                <br />
            </fieldset>
            <br />
            <hr />
            <div id="pnlform">
                <h2>
                    @(Model.Title)</h2>
                <p>
                    @(Model.Description)
                </p>
                @if (Model.FormSchemaXml.Section != null)
                {
                    foreach (BuildFormSection formSection in Model.FormSchemaXml.Section)
                    {
                    <fieldset  style="border:1px solid silver; padding:5px;">
                        <legend>
                            @(formSection.Name)</legend>
                        <ol>
                        @foreach (BuildFormSectionField formField in formSection.FormFields)
                        {
                            <li>
                                <label for="username">
                                    @(formField.Label):</label>
                                @if (formField.Type == "text")
                                {
                                    @(Html.TextBox(formField.ID, formField.Value))
                                }
                                else if (formField.Type == "textarea")
                                {
                                    @(Html.TextArea(formField.ID, formField.Value, new { @cols = "80", @rows = "4" }))
                                }
                                @if (formField.Type == "dropdown")
                                {
                                    @(Html.DropDownList(formField.ID, Model.GetDropdownValues(formField.ID, formField.Value)))
                                }
                                @if (formField.Type == "radio")
                                {
                                    Dictionary<string, bool> radioList = Model.GetMultiValues(formField.ID, formField.Value);
                                    foreach (KeyValuePair<string, bool> radioItem in radioList)
                                    {
                                    @(Html.RadioButton(formField.ID, radioItem.Key, radioItem.Value, new { @style = "width: 20px;"}))
                                    @(radioItem.Key + " ")
                                    }
                                }
                                @if (formField.Type == "checkbox")
                                {
                                    Dictionary<string, bool> checkvalueList = Model.GetMultiValues(formField.ID, formField.Value);
                                    foreach (KeyValuePair<string, bool> checkItemValue in checkvalueList)
                                    {
                                    @(Html.CheckBox(formField.ID + "_" + checkItemValue.Key, checkItemValue.Value))
                                    @(checkItemValue.Key + " ")
                                    }
                                }
                            </li>
                        }
                        </ol>
                    </fieldset>
                    }
                }
                <p style="text-align: center;">
                    <input type="submit" value="Submit" />
                </p>
                <br />
            </div>
    
        }
    </div>
